package com.fer.tankr.huds;

import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.fer.andenginemvc.api.PhysicsController;
import com.fer.tankr.MainActivity;
import com.fer.tankr.scenes.SceneManagerImpl;

public class PauseMenu extends HUD{

	final static int ITEM_RESUME = 1;
	final static int ITEM_MAIN_MENu = 2;
	
	private IMenuItem itemResume;
	private IMenuItem itemMainMenu;
	private MainActivity activity;
	private PhysicsController<?> controller;
	
	public PauseMenu(MainActivity activity, ITextureRegion textureResume, ITextureRegion textureMenu, final PhysicsController<?> controller) {
		VertexBufferObjectManager vbom = activity.getVertexBufferObjectManager();
		setBackground(new Background(0, 0, 0, 0));
		this.activity = activity;
		this.controller = controller;
		
		itemResume = new SpriteMenuItem(ITEM_RESUME,textureResume, vbom)
		{
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				PauseMenu.this.controller.resume();
				System.out.println("click!!!!!!!!!!!!!!!");
				return true;
			}
		};
		float x1 = activity.camera.getWidth()/2 - itemResume.getWidth()/2;
		float y1 = activity.camera.getHeight()/3 - itemResume.getHeight()/2;
		itemResume.setPosition(x1, y1);
		
		
		itemMainMenu = new SpriteMenuItem(ITEM_MAIN_MENu, textureMenu, vbom)
		{
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				PauseMenu.this.activity.setScene(SceneManagerImpl.MENU);
				return true;
			}
		};
		float x2 = activity.camera.getWidth()/2 - itemMainMenu.getWidth()/2;
		float y2 = 2*activity.camera.getHeight()/3 - itemMainMenu.getHeight()/2;
		itemMainMenu.setPosition(x2, y2);
		
		attachChild(itemMainMenu);
		attachChild(itemResume);
		 
		registerTouchArea(itemMainMenu);
		registerTouchArea(itemResume);
		
		setTouchAreaBindingOnActionDownEnabled(true);
	}

	
	
}
